/*
 * CharNode.h
 *
 *  Created on: 2017年6月20日
 *      Author: heqian
 */

#ifndef MMSEG_CHARNODE_H_
#define MMSEG_CHARNODE_H_

#include <string.h>
#include <string>
#include "EnumPos.h"

using namespace std;

typedef long long UTF_8;
#define UTF_SIZE(utf) *((unsigned char*)&utf + 7)
#define UTF_INIT(utf,val) utf = 0; *((unsigned char*)&utf + 7)= strlen(val); memcpy(&utf, val, *((unsigned char*)&utf + 7))
namespace mmseg {

class CharNode {
public:
	CharNode();
	virtual ~CharNode();

	const string& getOther() const;
	void setOther(const string& other);
	EnumPos getPos();
	void setPos(EnumPos pos);
	CharNode* find(UTF_8 key, bool isNew);
	CharNode** getNode();
	CharNode* getNext();

	UTF_8 getKey() const;

	void setKey(UTF_8 key);
	int getSize();
	int maxMatch(const char* str, int num, CharNode** out);
	bool isIsWord() const;
	void setIsWord(bool isWord);

private:
	string other;
	EnumPos pos;
	UTF_8 mKey;
	char* strKey;
	CharNode* mNode;
	CharNode* mNext;
	int mSize;
	bool isWord;
};

} /* namespace mmseg */

#endif /* MMSEG_CHARNODE_H_ */
